Component({
  properties: {
    visible: {
      type: Boolean,
      value: false,
      observer: 'toggleDialog'
    },
    title: {
      type: String, 
      value: '友情提示'
    },
    message: {
      type: String,
      value: ''
    }
  },
  data: {
    dialogVisible: false
  },
  methods: {
    toggleDialog(newVal) {
      if (newVal) {
        wx.showModal({
          title: this.data.title,
          content: this.data.message,
          success: (res) => {
            if (res.confirm) {
              this.triggerEvent('confirm');
            } else if (res.cancel) {
              this.triggerEvent('cancel');
            }
            this.setData({ dialogVisible: false });
          }
        });
      }
    }
  }
});
